#include "stdafx.h"
#include "Shape.h"

#include <memory>
#include <vector>
#include <algorithm>
#include <iostream>

/// Golable id generator
unsigned long g_basic_id = 1;

Shape::Shape(void)
{
	_id = g_basic_id++;
}

Shape::Shape(unsigned long id)
{
	_id = id;
}

Shape::~Shape(void)
{
}

std::vector<std::shared_ptr<Shape>> generateShapes(void)
{
	//std::vector<std::shared_ptr<Shape>> v;
	//for (int i = 0; i < 10; i++)
	//{
	//	v.push_back(std::make_shared<Circle>());
	//}

	// Refine using std::generate algorithm
	std::vector<std::shared_ptr<Shape>> v(10);
	std::generate(std::begin(v), std::end(v), [&] { return std::make_shared<Circle>(); });

	return v;
}

void ShapeAction(void)
{
	// Fake a smaple data
	std::shared_ptr<Shape> p = std::make_shared<Circle>(2);

	// Generate the shapes automatically
	auto v = generateShapes();

	// Find out the same id's shape
	std::for_each(std::begin(v), std::end(v), [&](const std::shared_ptr<Shape>& shape){
		if (shape && *p == *shape) {
			std::cout << "Found the right shape and the Id: " << (*shape).Id() << std::endl << std::endl;
			return;
		}
	});
}

// References:
// http://stackoverflow.com/questions/7593086/why-use-non-member-begin-and-end-functions-in-c11
// http://msdn.microsoft.com/en-us/library/windows/apps/hh279654.aspx
// http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-835T